package com.gxljc.bear.crawler.util;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by jianzhou on 2016/11/25.
 */
public class UrlUtil {
    public static Map<String, String> extractParams(String url) {
        try {
            URL urlo = new URL(url);
            Map<String, String> mapRequest = new HashMap<String, String>();
            String querys = urlo.getQuery();
            for (String qstr : querys.split("&")) {
                int idx = qstr.indexOf("=");
                String key = qstr.substring(0, idx);
                String value = qstr.substring(idx + 1, qstr.length());
                mapRequest.put(key, value);
            }
            return mapRequest;
        } catch (Exception e) {
            return null;
        }
    }
}
